<style>
    .layui-textarea{
        min-height: auto !important;
    }
</style>
<div class="layui-form" id="layuiadmin-form-admin" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">

    <div class="layui-col-xs12 layui-col-sm6 layui-col-md12">
	            <span style="color: red; font-size: 12px;float: left;
				    display: block;
				    padding: 9px 36px;
				    font-weight: 400;
				    line-height: 20px;
				    text-align: right;">备注:共有2种状态,分别为直接提交审核和存入草稿箱等待提交,默认为存入草稿箱状态</span>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">选择工作流</label>
                <div class="layui-input-block">
                    <select name="flow_id" lay-verify="required" lay-search="" disabled>
                        <option value="">直接选择或搜索选择</option>
                        {foreach $flow as $vo}
                        <option value="{$vo.id}" {if condition="($model.flow_id eq $vo.id)" }selected{/if}>{$vo.flowcode}-{$vo.flowname}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    提交状态
                </label>
                <div class="layui-input-block">
                    <input type="checkbox" id="status" lay-filter="switch" name="switch" lay-skin="switch"
                           value="{$model.status ?? 0}" lay-text="提交|草稿箱" {notempty name="model.status" }checked{/notempty}>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    日志年份
                </label>
                <div class="layui-input-block">
                    <select name="journal_year" id="journal_year" lay-verify="required"
                            lay-filter="journal_year" lay-search="" disabled>
                        <option value="">请选择日志类别</option>
                        <option value="2020" {if condition="($model.year eq 2020)" }selected{/if}>2020</option>
                        <option value="2021" {if condition="($model.year eq 2021)" }selected{/if}>2021</option>
                        <option value="2022" {if condition="($model.year eq 2022)" }selected{/if}>2022</option>
                        <option value="2023" {if condition="($model.year eq 2023)" }selected{/if}>2023</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    日志类别
                </label>
                <div class="layui-input-block">
                    <select name="journal_type_id" id="journal_type_id" lay-verify="required"
                            lay-filter="journal_type_id" lay-search="" disabled>
                        <option value="">请选择日志类别</option>
                        {foreach $journal_type as $key=>$vo}
                        <option value="{$vo.id}" {if condition="($model.journal_type_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    人员名称
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" id="period" name="admin_name"
                           value="{$model.admin_name ?? ''}" placeholder="请输入人员名称" required="" type="text" readonly>
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    所属部门
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" value="{$model.group_name ?? ''}" name="group_name"
                           placeholder="请输入所属部门" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div id="xinzeng"></div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" style="color: red;font-size: 12px;">
            <div class="layui-form-item">
                <label class="layui-form-label">

                </label>
                <div class="layui-input-block">
                    由于更换日志模板,请重新编写
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    内容填写
                </label>
                <div class="layui-input-block">
                    <table class="layui-table">
                        <tr>
                            <td style="text-align: center;">
                                日期
                            </td>
                            <td style="text-align: center;">
                                今日工作
                            </td>
                            <td style="text-align: center;">
                                工作进度
                            </td>
                        </tr>
                        {empty name="$model.week"}
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周一">周一
                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu"  name="jindu[]" />
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周二">周二
                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu"   name="jindu[]" />
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周三">周三

                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周四">
                                周四
                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周五">
                                周五

                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周六">
                                周六
                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <input type="hidden" name="xingqi[]" value="周日">
                                周日
                            </td>
                            <td style="text-align: center;">
                                <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                            </td>
                            <td style="text-align: center;">
                                <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                            </td>
                        </tr>
                        {else /}
                        <table class="layui-table">

                            {foreach $model.week as $key=>$vo }
                            <tr>
                                <td style="text-align: center;">
                                    <input type="hidden" name="week_id[]" value="{$vo.id ?? ''}">
                                    <input type="hidden" name="xingqi[]" value="{$vo.xingqi}">{$vo.xingqi ?? ''}
                                </td>
                                <td style="width: 90%">
                                    <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]">{$vo.content ?? ''}</textarea>
                                </td>
                                <td style="width: 10%">
                                    <input type="text" class="layui-input" id="jindu" value="{$vo.jindu ?? ''}" name="jindu[]" />
                                </td>
                            </tr>
                            {/foreach}
                        </table>
                        {/empty}
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-user-back-submit" id="LAY-user-back-submit" value="确认">
        </div>
    </div>
</div>

<script src="/static/admin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        treeTable: '../admin/lib/extend/authtree'
    }).use(['index', 'table','form'], function () {
        var $ = layui.$, form = layui.form, table = layui.table;

        table.init('demo', {
            size:"sm",
        });
        var year = $("#journal_year option:selected").val();
        var id = $("#journal_type_id option:selected").val();
        select_type(year,id);

        form.on('select(journal_year)', function (data) {
            select_type(data.value,$("#journal_type_id option:selected").val());
        });

        //监听指定开关
        form.on('switch(switch)', function (data) {
            if (data.othis = true) {
                $('#status').val(1);
            } else {
                $('#status').val(0);
            }
        });

        function select_type(year,id) {
            var html = "";
            var str = "";
            $.ajax({
                url: "{:url('journal/select_type')}",
                type: "post",
                data: {'year':year,'id': id},
                dataType: "json",
                success: function (res) {
                    var data = eval('(' + res + ')');
                    $("#xinzeng").empty();
                    html += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
                    html += "<div class=\"layui-form-item\">";
                    html += "<label class=\"layui-form-label\">第x" + $("#journal_type_id option:selected").text() + "</label>";
                    html += "<div class=\"layui-input-block\">";
                    html += "<select name=\"is_week\" id=\"is_week\" lay-verify=\"required\" lay-filter=\"is_week\">";
                    html += "<option value=\"\">请选择日志类别</option>";
                    str += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
                    str += "<div class=\"layui-form-item\">";
                    str += "<label class=\"layui-form-label\">所属范围</label>";
                    str += "<div class=\"layui-input-block\">";
                    $.each(data, function (index, el) {
                        if (el.detail == "{$model.is_week}") {
                            html += "<option value=\"" + el.detail + "\" data-name=\"" + el.fanwei + "\" selected>" + el.detail + "</option>";
                            str += "<input class=\"layui-input\" name=\"week_time\" id=\"week_time\" placeholder=\"请输入所属范围\" value=\"{$model.week_time ?? ''}\" required=\"\" type=\"text\" readonly /> ";
                        } else {
                            html += "<option value=\"" + el.detail + "\"  data-name=\"" + el.fanwei + "\">" + el.detail + "</option>";
                        }
                    });
                    html += " </select>";
                    html += "</div></div></div>";
                    str += "</div></div></div>";
                    $("#xinzeng").append(html);
                    $("#xinzeng").append(str);
                    form.render('select');
                }
            });
        }

        form.on('select(is_week)', function (event) {
            // var fanwei = $('#is_week').find("option:selected").data("name");
            var fanwei = event.elem[event.elem.selectedIndex].getAttribute('data-name');
            $('#week_time').val(fanwei);
        });
    });
</script>
